export const keyDept = "dept"
export const keyTeam = "team"
export const keyUser = "user"
import _ from 'lodash'
/**
 * 将科室数据重写
 * @param {*} arr 
 */
export function deptRewrite(arr) {
	return arr.map((item) => {
		return {
			// ...item,
			// _value: `dept-${item.deptId}`,
			label: item.deptName,
			value: JSON.stringify({
				key: keyDept,
				label: item.deptName,
				value: item.deptId,
			}),
			deptId: item.deptId,
			parentId: item.parentId,
			// _name: item.deptName,
			// _key: keyDept,
			// _orginValue: item.deptId
		}
	})
}
/**
 * 将科室和小组和人员的列表做一个重写
 */
export function deptAndGroupAndUserToRewrite(arr) {
	return arr.map(dept => {
		const {
			deptId: dept_value,
			teamList,
			deptName
		} = dept;
		const team_list = teamList.map(team => {
			const {
				teamId: team_value,
				userList,
				teamName
			} = team;
			const user_list = userList.map(user => {
				const {
					userId: user_value,
					nickName
				} = user;
				return {
					_path: `${nickName}/${teamName}/${deptName}`,
					userId: user_value,
					nickName,
					_teamId: team_value,
					_value: `user-${String(user_value)}`,
					_orginValue: user_value,
					_key: keyUser,
					_name: nickName,
					children: [],
					_valueObject: JSON.stringify({
						value: user_value,
						key: keyUser,
						// path: `${nickName}/${teamName}/${deptName}`,
						name: nickName,
						teamId: team_value,
						userId: user_value,
					})
				};
			});

			return {
				_key: keyTeam,
				_name: teamName,
				_value: `team-${String(team_value)}`,
				_orginValue: team_value,
				_path: `${teamName}/${deptName}`,
				_teamId: team_value,
				teamId: team.teamId,
				teamName: team.teamName,
				userList: user_list,
				children: user_list,
				_valueObject: JSON.stringify({
					value: team_value,
					key: keyTeam,
					// path: `${teamName}/${deptName}`,
					name: teamName,
					teamId: team.teamId,
					deptId: ''
				})
			};
		});

		return {
			_path: dept.deptName,
			_key: keyDept,
			_value: `dept-${String(dept_value)}`,
			_orginValue: dept_value,
			_name: dept.deptName,
			_teamId: '',
			deptId: dept.deptId,
			deptName: dept.deptName,
			teamList: team_list,
			children: team_list,
			_valueObject: JSON.stringify({
				value: dept_value,
				key: keyDept,
				// path: `${deptName}`,
				name: dept.deptName,
				deptId: dept.deptId,
				teamId: ""
			})
		};
	});
}


/**
 * 将 科室和小组和人员的列表 转换为只有小组和人员
 * @param {*} arr 
 */
export function deptAndTeamToRewrite(arr) {
	const list = arr.map(item => item.teamList)
	const _list = _.flatten(list)
	console.log(_list, 'arr');
	const result = [];
	_list.forEach(team => {
		const team_value = team.teamId;
		const user_list = [];
		team.userList.forEach(user => {
			const user_value = user.userId;
			user_list.push({
				_path: `${user.nickName}/${team.teamName}`,
				userId: user.userId,
				nickName: user.nickName,
				_value: `${keyUser}-${user_value}`,
				_orginValue: user_value,
				_key: keyUser,
				_name: user.nickName,
				_teamId: team_value
			});
		});

		result.push({
			_key: keyTeam,
			_name: team.teamName,
			_value: `${keyTeam}-${team_value}`,
			_orginValue: team_value,
			_path: `${team.teamName}`,
			_teamId: team_value,
			teamId: team_value,
			teamName: team.teamName,
			userList: user_list,
			children: user_list

		});

	});

	return result
}